/**
 * &copy; 2006 NewInstance.it
 */
package it.newinstance.jrainbow.converter;

import it.newinstance.jrainbow.source.Tag;
import it.newinstance.jrainbow.source.TaggedSource;
import it.newinstance.jrainbow.source.TaggedString;
import it.newinstance.jrainbow.source.TaggedStringIterator;

import java.io.IOException;

/**
 * @author Luigi R. Viggiano
 * @version $Id: AnyToHTMLConverter.java 138 2007-06-12 12:23:29Z luigi.viggiano $
 */
public class AnyToHTMLConverter extends HTMLConverter {

    public AnyToHTMLConverter() {
    }

    public void convert(TaggedSource source) throws IOException {
        if (getWriter() == null) 
            throw new IOException("Output not set for the converter. " +
                    "Please call setWriter method before convert.");
        emitSpanStart("code");
        for (TaggedString string : new TaggedStringIterator(source)) {
            Tag tag = string.getTag();
            emitSpanStart(tag);
            getWriter().write(htmlEncode(string.getString()));
            emitSpanEnd();
        }
        emitSpanEnd();
    }
    
}
